from ultralytics import YOLO

def main():
    model = YOLO("yolov8n.pt")
    model.train(
        data="dataset.yaml",
        epochs=100,
        imgsz=640,
        batch=12,
        workers=4   # 可适当减少避免 spawn 过多子进程
    )

if __name__ == "__main__":
    # Windows 下必须加这一句
    import multiprocessing
    multiprocessing.freeze_support()
    main()

'''
验证：
yolo detect val model=my_best.pt imgsz=640 data=dataset.yaml   
导出：
yolo export model=my_best.pt format=onnx # export custom trained model
'''